import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class Solution {
    public static void main(String[] args) {
        Arrays.asList();
    }
    public List<List<Integer>> threeSum(int[] nums) {
        Arrays.sort(nums);
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 0; i < nums.length-2 && nums[i] <= 0; i++) {
            if (i != 0 && nums[i] == nums[i-1]) {
                continue;
            }
            int left = i+1;
            int right = nums.length-1;
            while (left < right) {
                List<Integer> list1 = new ArrayList<>();
                if (left < right && left > i+1 && nums[left-1] == nums[left]) {
                    left++;
                    continue;
                }
                if (left < right && right+1 < nums.length && nums[right+1] == nums[right]) {
                    right--;
                    continue;
                }
                if (left < right && nums[i]+nums[left]+nums[right] == 0) {
                    list1.add(nums[i]);
                    list1.add(nums[left]);
                    list1.add(nums[right]);
                    list.add(list1);
                    left++;
                    right--;
                }else if (left < right && nums[i]+nums[left]+nums[right] < 0) {
                    left++;
                }else {
                    right--;
                }
            }
        }
        return list;
    }
}